//
//  StatusRetweetedViewFrame.m
//  Weibo
//
//  Created by Anasue on 9/16/15.
//  Copyright (c) 2015 Anasue. All rights reserved.
//

#import "StatusRetweetedViewFrame.h"
#import "Status.h"
#import "User.h"
#import "StatusPhotosView.h"

@implementation StatusRetweetedViewFrame

- (void)setRetweetedStatus:(Status *)retweetedStatus
{
    _retweetedStatus = retweetedStatus;
    
    //1.设置昵称frame
//    CGFloat nameX = StatusCellInSet;
//    CGFloat nameY = StatusCellInSet;
//    NSMutableDictionary *nameAttr = [NSMutableDictionary dictionary];
//    nameAttr[NSFontAttributeName] =StatusRetweetedNameFont;
//    NSString *str = [NSString stringWithFormat:@"@%@",retweetedStatus.user.name];
//    CGSize nameSize = [str sizeWithAttributes:nameAttr];
//    self.nameFrame = (CGRect){{nameX,nameY},nameSize};
    
    //2.设置正文frame
    CGFloat textX = StatusCellInSet;
    CGFloat textY = StatusCellInSet * 0.5;
    NSMutableDictionary *textAttr = [NSMutableDictionary dictionary];
    textAttr[NSFontAttributeName] = StatusRetweetedTextFont;
    CGFloat maxW = ScreenW - 2 * textX;
    CGSize maxSize = CGSizeMake(maxW, MAXFLOAT);
//    CGSize textSize = [retweetedStatus.text sizeWithFont:StatusRetweetedTextFont constrainedToSize:maxSize];
    CGSize textSize = [retweetedStatus.attributedText boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin context:nil].size;
    self.textFrame = (CGRect){{textX,textY},textSize};
    
    //3.设置配图frame
    CGFloat h = 0;
    if (retweetedStatus.pic_urls.count) {
        CGFloat photosX = textX;
        CGFloat photosY = CGRectGetMaxY(self.textFrame) + StatusCellInSet * 0.5;
        CGSize photosSize = [StatusPhotosView sizeWithPhotosCount:(int)retweetedStatus.pic_urls.count];
        self.photosFrame = (CGRect){{photosX,photosY},photosSize};
        //        Log(@"%@",NSStringFromCGRect(self.photosFrame));
        h = CGRectGetMaxY(self.photosFrame) + StatusCellInSet;
    }else{
        h = CGRectGetMaxY(self.textFrame) + StatusCellInSet;
    }
    
    //3.设置自己frame
    CGFloat x = 0;
    CGFloat y = 0;
    CGFloat w = ScreenW;
//    CGFloat h = CGRectGetMaxY(self.textFrame) + StatusCellInSet;
    self.frame = CGRectMake(x, y, w, h);

}

@end
